{extend name="public/base"/}
{block name="style"}
<link rel="stylesheet" href="__PUBLIC__/css/print.min.css">
{/block}
{block name="content"}
    <div class="data-list" data-url="{:url('index')}">
        <form class="layui-form inline-form">
            <div class="pull-left">
                <div class="layui-inline">
                    <input type="text" autofocus placeholder="SPU/SKU" name="sku" class="layui-input">
                </div>
                <div class="layui-inline">
                    <select name="account_id" lay-search lay-filter="data-list">
                        <option value="">销售账号</option>
                        {foreach $accounts as $account}
                        <option value="{$account.account_id}">{$account.username}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="is_merge" lay-search lay-filter="data-list">
                        <option value="">是否合成</option>
                        {foreach $is_merge as $k=>$v}
                        <option value="{$k}">{$v}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="status" lay-search lay-filter="data-list">
                        <option value="">是否可用</option>
                        {foreach $status as $k=>$v}
                        <option value="{$k}">{$v}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm layui-btn-normal search"><i class="layui-icon layui-icon-search"></i></button>
                </div>
                <input type="hidden" id="upload-file">
            </div>
            <div class="pull-right">
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-normal layui-btn-sm ajax-form" title="添加平台条码" data-url="{:url('add')}"><i class="layui-icon layui-icon-add-circle"></i> 新增</button>
                </div>
            </div>
        </form>
        <div class="data">
            <p><i class="fa fa-spinner fa-spin"></i> 加载中...</p>
        </div>
    </div>
{/block}
{block name="script"}
<script type="text/javascript" src="__PUBLIC__/js/print.min.js"></script>
<script type="text/javascript">
    layui.use(['layer', 'upload'], function()
    {
        var upload = layui.upload
            , layer = layui.layer;

        upload.render({
            elem: '#upload-file' //绑定元素
            ,url: '{:url("file/upload",["type"=>"document"])}' //上传接口
            , accept: 'file' //普通文件
            , exts: 'pdf' // 指定类型
            , before: function (obj) {
                layer.load(0, {shade: false});
            }
            ,done: function(response)
            {
                layer.closeAll('loading');
                if (response.code == 1)
                {
                    var item = $("#upload-file").attr("item");
                    if(item == "pm")
                    {
                        $("#barcode-pm-path").val(response.data.src);
                    }
                    else if(item == "merge")
                    {
                        $("#barcode-merge-path").val(response.data.src);
                    }
                }
            }
        });
        $("body").on("click", ".upload-pdf", function()
        {
            var $upload = $("#upload-file");
            $upload.removeAttr("item").attr("item", $(this).is("#pm-upload-btn") ? "pm" : "merge").click();
        });
        $("body").on("click", ".pdf-do-print", function()
        {
            var $this = $(this)
                , pdfUrl = $this.attr("item");
            if(!pdfUrl)
            {
                layer.msg("未生成PDF, 请先生成或上传", {icon: 5, time: 1500});
                return false;
            }
            printJS({printable: pdfUrl, type:'pdf', showModal:true});
        });
    });
</script>
{/block}